package edu.scu.declaresys.vo;

import java.util.List;

import edu.scu.declaresys.dao.util.Column;
import edu.scu.declaresys.dao.util.FieldWalker;
import edu.scu.declaresys.dao.util.Table;

/**
 * 
 * @author: zt
 * @since : 2013-7-3
 */
@Table(code = Area.T_TABLE)
public class Area implements java.io.Serializable
{
	private static final long	serialVersionUID	= -3631207280279001395L;
	//
	// table column name.
	//
	public static final String	T_TABLE				= "area";
	public static final String	T_ID				= "id";
	public static final String	T_PARENT_ID			= "parentId";
	public static final String	T_LEVEL				= "level";
	public static final String	T_NAME				= "name";
	//
	//
	//
	public static final int PROVINCE_ID = 1;
	public static final int NULL_AREA_ID = -1;
	//
	// 地区级别
	//
	public static final int LEVEL_COUNTY = 1;
	public static final int LEVEL_CITY = 2;
	public static final int LEVEL_PROVINCE = 3;
	//
	// Fields
	//
	@Column(code = T_ID)
	private Integer				id;
	
	@Column(code=T_PARENT_ID)
	private Integer parentId;
	
	@Column(code = T_LEVEL)
	private Integer				level;
	
	@Column(code = T_NAME)
	private String				name;
	//
	// Reference
	//
	private Area parent;
	private List<Area> children;
	//
	// Constructors
	//
	/** default constructor */
	public Area()
	{
	}
	
	
	public Area(Integer id, Integer parentId, Integer level, String name)
	{
		super();
		this.id = id;
		this.parentId = parentId;
		this.level = level;
		this.name = name;
	}


	//
	// Override functions.
	//
	public String toString()
	{
		return FieldWalker.makeNonstaticFields(this, FieldWalker.WITHOUT_NULL);
	}
	
	@Override
	public int hashCode()
	{
		return id.hashCode();
	}

	@Override
	public boolean equals(Object obj)
	{
		if(this == obj)
		{
			return true;
		}
		if(obj == null)
		{
			return false;
		}
		if(!(obj instanceof Area))
		{
			return false;
		}
		//
		return this.id.equals(((Area)obj).id);
	}
	
	public boolean isCounty()
	{
		return Area.LEVEL_COUNTY == level;
	}
	
	public boolean isCity()
	{
		return Area.LEVEL_CITY == level;
	}
	
	public boolean isProvince()
	{
		return Area.LEVEL_PROVINCE == level;
	}
	
	//
	// Property accessors
	//
	public Integer getId()
	{
		return this.id;
	}
	
	public void setId(Integer id)
	{
		this.id = id;
	}
	
	public Integer getParentId()
	{
		return parentId;
	}


	public void setParentId(Integer parentId)
	{
		this.parentId = parentId;
	}


	public Integer getLevel()
	{
		return this.level;
	}
	
	public void setLevel(Integer level)
	{
		this.level = level;
	}
	
	public String getName()
	{
		return this.name;
	}
	
	public void setName(String name)
	{
		this.name = name;
	}

	public Area getParent()
	{
		return parent;
	}
	public void setParent(Area parent)
	{
		this.parent = parent;
	}


	public List<Area> getChildren()
	{
		return children;
	}


	public void setChildren(List<Area> children)
	{
		this.children = children;
	}
}
